import Block from "./block.js";
import Event from "./event.js";
import Game from "./game.js";

export default class Destriable extends Block {
  constructor(x,y,width,height,imgSrc,life){
    super(x,y,width,height,imgSrc);
    this.life = life;
    this.event = new Event();
  }
  takeDamage(source){
    this.life -= source.attack;
    this.event.trigger('onDamage',null,this);
    if(this.life <= 0){
      this.event.trigger('onDestroy',new Game(),this);
    }
  }
}